package com.googlecode.lohr.tools.interpreter;

import lohr.lang.dom.SlotDefinition;

public class SlotDefinitionImpl extends ExpressionImpl {
	
	ExpressionImpl _initExpression;
	
	String _slotName;
	AccessType _accessType;

	public SlotDefinitionImpl(LohrInterpreter interpreter, SlotDefinition expression) {
		super(interpreter, expression);
		_initExpression= ExpressionImpl.createExpressionImpl(interpreter, expression.getInitExpression());
		_slotName= expression.getSlotIdentifier().getName();
		_accessType= AccessType.valueOf(expression.getModifier().getDescription().toUpperCase());
	}

	@Override
	public ObjectImpl invoke(ObjectImpl invocationContext, Locals arguments) {
		ObjectImpl slotValue= _initExpression.invoke(invocationContext, arguments);
		invocationContext.createSlot(_accessType, _slotName, slotValue);
		return slotValue;
	}

}
